module maths.Misc;

private {
	import std.math;
}



const real deg2rad	= 0.0174532925199432957692369076848861;
const real rad2deg	= 57.2957795130823208767981548141052;
const real pi			= 3.1415926535897932384626433832795;



void cartesianToSpherical(real x, real y, real z, real* phi, real* theta, real* r)
out {
	assert (*phi >= -pi - 0.001 && *phi <= pi + 0.001);
	assert (*theta >= -0.001 && *theta <= pi + 0.001);
}
body {
	*r			= sqrt(x*x+y*y+z*z);
	*phi		= atan2(y, x);
	*theta	= acos(z / *r);
}


void cartesianToSpherical(real x, real y, real z, real* phi, real* theta)
in {
	real r = sqrt(x*x+y*y+z*z);
	assert (r >= 0.999 && r <= 1.001);
}
out {
	assert (*phi >= -pi - 0.001 && *phi <= pi + 0.001);
	assert (*theta >= -0.001 && *theta <= pi + 0.001);
}
body {
	*phi		= atan2(y, x);
	*theta	= acos(z);
}
